package bishi;

import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;

/**
 * @Author liuhaoqi
 * @Date 2020/9/26 15:17
 * @Version 1.0
 */
public class Pufa03 {
    public static void main(String[] args) {
        String str = "lpr*(1+5.39-4.8)";
        int b = pufa03(str);
        System.out.println(b);
    }

    public static int pufa03(String str) {
        HashMap<Character,Character> map = new HashMap(){{
            put(')', '(');
            put(']', '[');
            put('}', '{');
        }};
        Deque<Character> stack =new LinkedList<>();
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '(' || str.charAt(i) == ')') {
                if (map.containsKey(str.charAt(i))) {
                    if (!map.get(str.charAt(i)).equals(stack.peek())) {
                        return 0;
                    }
                    stack.pop();
                } else {
                    stack.push(str.charAt(i));
                }
            }

        }
        if (stack.isEmpty()) {
            return 1;
        } else {
            return 0;
        }
    }
}
